package com.iwhalecloud.citybrain.flow.platform.manager.application.service.impl;

import com.iwhalecloud.citybrain.flow.platform.manager.application.service.AbstractEntityEventHandler;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.repository.FlowProcessInstanceTraceRepository;
import com.iwhalecloud.citybrain.flow.platform.manager.application.utils.SpringUtils;
import org.flowable.engine.common.api.delegate.event.FlowableEngineEventType;
import org.flowable.engine.common.api.delegate.event.FlowableEventType;
import org.flowable.engine.delegate.event.impl.FlowableEntityEventImpl;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
import org.springframework.stereotype.Component;

/**
 * Handler - 流程实例完成后事件处理
 *
 * @author lilh
 * @date 2019-01-28 16:02
 */
@Component
public class ProcessInstanceCompletedHandler extends AbstractEntityEventHandler {

    @Override
    public FlowableEventType getEventType() {
        return FlowableEngineEventType.PROCESS_COMPLETED;
    }

    @Override
    protected void doHandle(FlowableEntityEventImpl event) {
        ExecutionEntityImpl executionEntity = (ExecutionEntityImpl) event.getEntity();
        FlowProcessInstanceTraceRepository processInstanceTraceService = SpringUtils.getBean(FlowProcessInstanceTraceRepository.class);
        processInstanceTraceService.updateLinkStatusToEnd(executionEntity.getProcessInstanceId());
    }
}
